<template>
  <a-modal v-model="visible" on-ok="handleOk" @cancel="handleCancel" :width="400">
    <template slot="title">

    </template>
    <template slot="footer">
      <a-button key="back" @click="handleOverrule" :loading="loading">
        驳回
      </a-button>
      <a-button key="submit" type="primary" :loading="loading" @click="handleOk">
        通过
      </a-button>
    </template>
    <a-row :gutter="48">
      <a-col :span="2">
        <a-icon type="question-circle" :style='{"font-size":"22px"}' theme="twoTone" two-tone-color="#faad14"/>
      </a-col>
      <a-col :span="19">
        <div class="ant-modal-confirm-body">
          <span class="ant-modal-confirm-title">是否确认审核{{num}}条数据？</span>
          <div class="ant-modal-confirm-content">数据审核后将不可编辑、不可删除，如果需要编辑、删除，请先对数据进行反审核。</div>
        </div>
      </a-col>
    </a-row>
  </a-modal>
</template>

<script>
  import {getAction} from '@/api/manage'

  export default {
    name: "AuditModal",
    data() {
      return {
        loading: false,
        visible: false,
        num: 1,
        ids: '',
        url: {
          audit: "",
          auditBatch: "",
          overrule: "",
          overruleBatch: "",
        }
      };
    },
    methods: {
      showModal(ids, num) {
        if (!num) {
          num = 1;
        }
        this.num = num;
        this.ids = ids;
        this.visible = true;
      },
      handleOk(e) {
        let that = this;
        that.loading = true;
        let url;
        let param;
        if (that.ids.indexOf(',') == -1) {
          url = that.url.audit;
          param = {id: that.ids}
        } else {
          url = that.url.auditBatch;
          param = {ids: that.ids}
        }
        getAction(url, param).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.$emit('ok');
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
          that.close();
        });
      },
      close() {
        this.$emit('close');
        this.visible = false;
      },
      handleOverrule(e) {
        let that = this;
        that.loading = true;
        let url;
        let param;
        if (that.ids.indexOf(',') == -1) {
          url = that.url.overrule;
          param = {id: this.ids}
        } else {
          url = that.url.overruleBatch;
          param = {ids: this.ids}
        }
        getAction(url, param).then((res) => {
          if (res.success) {
            that.$message.success(res.message);
            that.$emit('ok');
          } else {
            that.$message.warning(res.message);
          }
        }).finally(() => {
          that.loading = false;
          that.close();
        });
      },
      handleCancel(e) {
        this.visible = false;
      },
    },
  }
</script>

<style scoped>

</style>